<!-- 添加学生 -->
<template>
  <section class="add">
    <el-form ref="form" :model="form_stu" label-width="80px">
      <el-form-item label="姓名">
        <el-input v-model="form_stu.sname"></el-input>
      </el-form-item>
      <el-form-item label="性别">
        <el-input v-model="form_stu.gender"></el-input>
      </el-form-item>
<!--      <el-form-item label="学院">-->
<!--        <el-input v-model="form_stu.institute"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="专业">
        <el-input v-model="form_stu.major"></el-input>
      </el-form-item>
<!--      <el-form-item label="年级">-->
<!--        <el-input v-model="form_stu.grade"></el-input>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="班级">-->
<!--        <el-input v-model="form_stu.clazz"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="电话号码">
        <el-input v-model="form_stu.phoneNumber"></el-input>
      </el-form-item>

      <el-form-item label="邮箱">
        <el-input v-model="form_stu.email"></el-input>
      </el-form-item>

      <el-form-item label="学号">
        <el-input v-model="form_stu.sno"></el-input>
      </el-form-item>

      <el-form-item label="密码">
        <el-input v-model="form_stu.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit()">立即创建</el-button>
        <el-button type="text" @click="cancel()">取消</el-button>
      </el-form-item>
    </el-form>
  </section>
</template>

<script>
export default {
  data() {
    return {
      form_stu: { //表单数据初始化
        sname: null,
        // grade: null,
        major: null,
        // clazz: null,
        // institute: null,
        phoneNumber: null,
        email: null,
        password: null,
        sno: null,
        gender: null,
        role: 2
      }
    };
  },
  methods: {
    onSubmit() { //数据提交
      this.$axios({
        url: '/api/student',
        method: 'post',
        data: {
          ...this.form_stu
        }
      }).then(res => {
        if(res.data.code == 200) {
          this.$message({
            message: '数据添加成功',
            type: 'success'
          })
          this.$router.push({path: '/studentManage'})
        }
      })
    },
    cancel() { //取消按钮
      this.form_stu = {}
    },

  }
};
</script>
<style lang="less" scoped>
.add {
  padding: 0px 40px;
  width: 400px;
}
</style>

